import Vue from 'vue'
import Vuex from 'vuex'
import vuexPersist from 'vuex-persistedstate';
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    unreadList: [], // 未读的列表
    readList: [], // 已读的列表
    recycle: [], // 回收站的列表
  },
  mutations: {
    sendList(state, pload) {
      // if (pload.style == 'unread'){
      //   // state.unreadList = pload.list
      //   let str = state.unreadList.splice(pload.index,1);
      //   // console.log(str); 
      //   // [...state.readList,...str] 数组的合并 扩展运算符
      //   state.readList = [...state.readList,...str];
      //   // state.readList.push(str[0])
      //   // let arr = [1,2,3,4,5]
      //   // let arr1 = [5,6,7,8]
      //   // let arr2 = [...arr,...arr1]
      //   // console.log(arr2);
      //   // console.log(state.readList);
      // } else if (pload.style == 'read'){
      //   state.unreadList = [...state.unreadList,...state.readList.splice(pload.index,1)]
      // } else {
      //   state.recycle = [...state.recycle,...state.readList.splice(pload.index,1)]
      // }


      switch (pload.style) {
        case 'unread':
          state.readList = [...state.readList, ...state.unreadList.splice(pload.index, 1)];
          break;
        case 'read':
          state.unreadList = [...state.unreadList, ...state.readList.splice(pload.index, 1)];
          break;
        case 'recycle':
          state.recycle = [...state.recycle, ...state.readList.splice(pload.index, 1)]
          break;
        default:
          state.unreadList = [...state.unreadList, ...state.recycle.splice(pload.index, 1)]
      }
    },
    allList(state,pload){
      switch (pload) {
        case 'unread':
          state.readList = [...state.readList, ...state.unreadList];
          state.unreadList = [];
          break;
        case 'read':
          state.unreadList = [...state.unreadList, ...state.readList];
          state.readList = []
          break;
        case 'recycle':
          state.unreadList = [...state.unreadList, ...state.recycle]
          state.recycle = [];
          break;
      }
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    })
  ],
})
